{% extends 'admin/common/base.html' %}
{% block css %}
{{super()}}
<link href="{{url_for('admin.static',filename='ajax/libs/select2/select2.min.css')}}" rel="stylesheet"/>
<link href="{{url_for('admin.static',filename='ajax/libs/select2/select2-bootstrap.css')}}" rel="stylesheet"/>
<link href="{{url_for('admin.static',filename='ajax/libs/jquery-ztree/3.5/css/metro/zTreeStyle.css')}}" rel="stylesheet"/>
<link href="{{url_for('admin.static',filename='ajax/libs/jasny/jasny-bootstrap.min.css')}}?v=3.1.3" rel="stylesheet"/>
<style type="text/css">.user-info-head{position:relative;display:inline-block;}.user-info-head:hover:after{content:'\f030';position:absolute;left:0;right:0;top:0;bottom:0;color:#eee;background:rgba(0,0,0,0.5);font-family:FontAwesome;font-size:24px;font-style:normal;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;cursor:pointer;line-height:110px;border-radius:50%;}</style>
{% endblock %}
{% block body %}
<body class="gray-bg" style="font: 14px Helvetica Neue, Helvetica, PingFang SC, 微软雅黑, Tahoma, Arial, sans-serif !important;">
    <input id="userId" name="userId" type="hidden" value="{{user.id}}" />
    <section class="section-content">
    <div class="row">
        <div class="col-sm-3 pr5">
            <div class="ibox float-e-margins">
                <div class="ibox-title ibox-title-gray dashboard-header gray-bg">
                    <h5>个人资料</h5>
                </div>
                <div class="ibox-content">
                    <div class="text-center">
                        {% set profile_img = url_for('admin.static',filename='img/profile.jpg') %}
                        <p class="user-info-head" onclick="avatar()"><img class="img-circle img-lg" src="{{user.avatar}}" onerror="this.src='{{profile_img}}';"></p>
                        <p><a href="javascript:avatar()">修改头像</a></p>
                    </div>
                    <ul class="list-group list-group-striped">
                        <li class="list-group-item"><i class="fa fa-user"></i>
                            <b class="font-noraml">用户：</b>
                            <p class="pull-right">{{user.name}}</p>
                        </li>
                        <li class="list-group-item"><i class="fa fa-phone"></i>
                            <b  class="font-noraml">手机号码：</b>
                            <p class="pull-right">{{user.mobile}}</p>
                        </li>
                        <li class="list-group-item"><i class="fa fa-group"></i>
                            <b  class="font-noraml">部门：</b>
                            <p class="pull-right" style="overflow: hidden; white-space: nowrap; text-overflow: ellipsis;width:120px;">{{user.org.name}}</p>
                        </li>
                        <li class="list-group-item"><i class="fa fa-envelope-o"></i>
                            <b  class="font-noraml">邮箱地址：</b>
                            <p class="pull-right" title="{{user.email}}">{{user.email}}</p>
                        </li>
                        <li class="list-group-item"><i class="fa fa-calendar"></i>
                            <b  class="font-noraml">创建时间：</b>
                            <p class="pull-right">{{ user.ctime.strftime("%Y-%m-%d") }}</p>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
        
        <div class="col-sm-9 about">
            <div class="ibox float-e-margins">
                <div class="ibox-title ibox-title-gray dashboard-header">
                    <h5>基本资料</h5>
                </div>
                <div class="ibox-content">
                    <div class="nav-tabs-custom">
                        <ul class="nav nav-tabs">
                            <li class="active"><a href="#user_info" data-toggle="tab" aria-expanded="true">基本资料</a></li>
                            <li><a href="#modify_password" data-toggle="tab" aria-expanded="false">修改密码</a></li>
                        </ul>
                        <div class="tab-content">
                            <!--用户信息-->
                            <div class="tab-pane active" id="user_info">
                                <form class="form-horizontal" id="form-user-edit">
                                    <!--隐藏ID-->
                                    <input name="id" id="id" type="hidden" value="{{user.id}}">
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">用户名称：</label>
                                        <div class="col-sm-10">
                                            <input type="text" class="form-control" name="name" placeholder="请输入用户名称" id="name" value="{{user.name}}">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">手机号码：</label>
                                        <div class="col-sm-10">
                                            <input type="text" class="form-control" name="mobile" maxlength="11" placeholder="请输入手机号码" id="mobile" value="{{user.mobile}}" readonly>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">邮箱：</label>
                                        <div class="col-sm-10">
                                            <input type="text" maxlength="50" class="form-control" name="email" placeholder="请输入邮箱" id="email" value="{{user.email}}">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">性别：</label>
                                        <div class="col-sm-10">
                                            <div class="radio-box">
												<input type="radio" id="radio1" name="sex" value="男" {% if user.sex == '男' %}checked="checked" {% endif %}>
												<label for="radio1">男</label>
											</div>
											<div class="radio-box">
												<input type="radio" id="radio2" name="sex" value="女" {% if user.sex == '女' %}checked="checked" {% endif %}>
												<label for="radio2">女</label>
											</div>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <div class="col-sm-offset-2 col-sm-10">
                                            <button type="button" class="btn btn-sm btn-primary" onclick="submitUserInfo()"><i class="fa fa-check"></i>保 存</button>&nbsp;
                                            <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                            
                            <!--修改密码-->
                            <div class="tab-pane" id="modify_password">
                                <form class="form-horizontal" id="form-user-resetPwd">
                                    <!--隐藏ID-->
                                    <input name="id" id="id" type="hidden" value="{{user.id}}">
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">旧密码：</label>
                                        <div class="col-sm-10">
                                            <input type="password" class="form-control" name="oldPassword" placeholder="请输入旧密码">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">新密码：</label>
                                        <div class="col-sm-10">
                                            <input type="password" class="form-control" name="newPassword" id="newPassword" placeholder="请输入新密码">
                                             
						                        
						                    
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">确认密码：</label>
                                        <div class="col-sm-10">
                                            <input type="password" class="form-control" name="confirmPassword" placeholder="请确认密码">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <div class="col-sm-offset-2 col-sm-10">
                                            <button type="button" class="btn btn-sm btn-primary" onclick="submitChangPassword()"><i class="fa fa-check"></i>保 存</button>&nbsp;
                                            <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
	</section>
</body>
{% endblock %}
{% block js %}
{{ super() }}
<script src="{{url_for('admin.static',filename='ajax/libs/select2/select2.min.js')}}"></script>
<script src="{{url_for('admin.static',filename='ajax/libs/jquery-ztree/3.5/js/jquery.ztree.all-3.5.js')}}"></script>
<script src="{{url_for('admin.static',filename='ajax/libs/jasny/jasny-bootstrap.min.js')}}?v=3.1.3"></script>
<script>
    var ctx = '';
    /*用户管理-头像*/
    function avatar() {
        var url = "{{url_for('admin.sys.user.profile_avatar')}}";
        top.layer.open({
            type: 2,
            area: [$(window).width() + 'px', $(window).height() + 'px'],
            fix: false,
            //不固定
            maxmin: true,
            shade: 0.3,
            title: "修改头像",
            content: url,
            btn: ['确定', '关闭'],
            // 弹层外区域关闭
            shadeClose: true,
            yes: function(index, layero) {
                var iframeWin = layero.find('iframe')[0];
                iframeWin.contentWindow.submitHandler(index, layero);
            },
            cancel: function(index) {
                return true;
            }
        });
    }

    /*用户信息-修改*/
    $("#form-user-edit").validate({
        onkeyup: false,
        rules:{
            username:{
                minlength: 2,
                maxlength: 20,
                remote: {
                    url: "{{url_for('admin.sys.user.check_username_unique')}}",
                    type: "post",
                    dataType: "json",
                    data: {
                        'user_id': function() {
                            return $("#id").val();
                        },
                        "username": function() {
                            return $.common.trim($("#username").val());
                        }
                    },
                    dataFilter: function(data, type) {
                        return $.validate.unique(data);
                    }
                }
            },
            email:{
                required:true,
                email:true
            },
            mobile:{
        		isPhone:true,
                remote: {
                    url: "{{url_for('admin.sys.user.check_mobile_unique')}}",
                    type: "post",
                    dataType: "json",
                    data: {
                        'user_id': function() {
                            return $("#id").val();
                        },
                        "mobile": function () {
                            return $.common.trim($("#mobile").val());
                        }
                    },
                    dataFilter: function (data, type) {
                        return $.validate.unique(data);
                    }
                }
        	},
        },
        messages: {
            "username": {
                required: "请输入用户名称",
                remote: "用户已经存在"
            },
            "email": {
                required: "请输入邮箱",
                remote: "Email已经存在"
            },
            "mobile":{
                required: "请输入手机号码",
                remote: "手机号码已经存在"
            }
        },
        focusCleanup: true
    });
    
    function submitUserInfo() {
        if ($.validate.form()) {
            $.operate.saveModal("{{url_for('admin.sys.user.edit')}}", $('#form-user-edit').serialize());
        }
    }
    
    /*用户管理-修改密码*/
    $("#form-user-resetPwd").validate({
        onkeyup: false,
        rules:{
            oldPassword:{
                required:true,
                remote: {
                    url: "{{url_for('admin.sys.user.check_pwd')}}",
                    type: "get",
                    dataType: "json",
                    data: {
                        password: function() {
                            return $("input[name='oldPassword']").val();
                        }
                    }
                }
            },
            newPassword: {
                required: true,
                minlength: 6,
                maxlength: 20
            },
            confirmPassword: {
                required: true,
                equalTo: "#newPassword"
            }
        },
        messages: {
            oldPassword: {
                required: "请输入原密码",
                remote: "原密码错误"
            },
            newPassword: {
                required: "请输入新密码",
                minlength: "密码不能小于6个字符",
                maxlength: "密码不能大于20个字符"
            },
            confirmPassword: {
                required: "请再次输入新密码",
                equalTo: "两次密码输入不一致"
            }

        },
        focusCleanup: true
    });


    $("#form-sys-set").validate({
        onkeyup: false,
        rules:{
        },
        messages: {
        },
        focusCleanup: true
    });

    
    function submitChangPassword () {
        var chrtype = 0;
        var password = $("#newPassword").val();
        if ($.validate.form("form-user-resetPwd") && checkpwd(chrtype, password)) {
            $.operate.saveModal("{{url_for('admin.sys.user.profile_reset_pwd')}}", $('#form-user-resetPwd').serialize());
        }
    }
    
</script>
{% endblock %}
